package com.souche.employment.mapper;

import com.souche.employment.domain.EmployeeDO;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * userMapper.java created at 2017年8月9日 下午2:23:36
 *
 * @author Ray [email:rayinhangzhou@hotmail.com]
 * Revision History
 * Date            Programmer                   Notes
 * ----------------------------------------------------------
 **/
@Mapper
public interface EmployeeMapper {

    @Select("select * from employee where id = #{id}")
    @Results({
            @Result(property = "workAge", column = "work_age"),
            @Result(property = "jobId", column = "job_id"),
            @Result(property = "jobName", column = "job_name"),
            @Result(property = "inviteStatus", column = "invite_status"),
            @Result(property = "interviewStatus", column = "interview_status"),
            @Result(property = "interviewTime", column = "interview_time"),
            @Result(property = "interviewType", column = "interview_type"),
            @Result(property = "dateCreate", column = "date_create")
    })
    EmployeeDO get(String id);

    @Insert("insert into employee (id, name, gender, age, work_age, phone, mail, pipe, referee, tips, job_id, job_name," +
            "dep1, dep2, invite_status, interview_status, interview_time, interview_type, interviewer0, interviewer1, " +
            "interviewer2, file, creator, date_create) values(#{id}, #{name}, #{gender}, #{age}, #{workAge}, #{phone}, " +
            "#{mail}, #{pipe}, #{referee}, #{tips}, #{jobId}, #{jobName}, #{dep1}, #{dep2}, #{inviteStatus}, #{interviewStatus}, " +
            "#{interviewTime}, #{interviewType}, #{interviewer0}, #{interviewer1}, #{interviewer2}, #{file}, #{creator}, now())")
    void add(EmployeeDO employeeDO);

    @Update("update employee set name=#{name}, gender=#{gender}, age=#{age}, work_age=#{workAge}, phone=#{phone}, mail=#{mail}, " +
            "pipe=#{pipe}, referee=#{referee}, tips=#{tips}, job_id=#{job_id}, job_name=#{job_name}, dep1=#{dep1}, dep2=#{dep2}, " +
            "interview_time=#{interviewTime}, " +
            "interview_type=#{interviewType}, interviewer0=#{interviewer0}, interviewer1=#{interviewer1}, interviewer2=#{interviewer2} where id=#{id} ")
    void update(EmployeeDO employeeDO);

    @Update("update employee set invite_status=#{inviteStatus}, interview_time=#{interviewTime}, interview_type=#{interviewType} where id=#{id} ")
    void updateInviteStatus(EmployeeDO employeeDO);

    @Update("update employee set interview_status=#{interviewStatus} where id=#{id} ")
    void updateInterviewStatus(EmployeeDO employeeDO);

    @Update("update employee set file=#{file} where id=#{id} ")
    void updateFile(EmployeeDO employeeDO);

    @Select("select * from employee order by date_update desc")
    @Results({
            @Result(property = "jobId", column = "job_id"),
            @Result(property = "jobName", column = "job_name"),
            @Result(property = "inviteStatus", column = "invite_status"),
            @Result(property = "interviewStatus", column = "interview_status"),
            @Result(property = "dateCreate", column = "date_create")
    })
    List<EmployeeDO> getListForEs();

    @SelectProvider(type = SqlProvider.class, method = "findInterviews")
    @Results({
            @Result(property = "workAge", column = "work_age"),
            @Result(property = "jobId", column = "job_id"),
            @Result(property = "jobName", column = "job_name"),
            @Result(property = "inviteStatus", column = "invite_status"),
            @Result(property = "interviewStatus", column = "interview_status"),
            @Result(property = "interviewTime", column = "interview_time"),
            @Result(property = "interviewType", column = "interview_type"),
            @Result(property = "dateCreate", column = "date_create")
    })
    List<EmployeeDO> getListForInterview(@Param("hr") String hr, @Param("dep1") String dep1, @Param("dep2") String dep2,
                                         @Param("interviewTime0") Date interviewTime0, @Param("interviewTime1") Date interviewTime1, @Param("sort") String sort);
}
